package userInterface;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class UserMenu extends JDialog implements ActionListener {
    JPanel[] jPanels = new JPanel[3];
    String[] prompt = { "存款", "取款", "转账", "投资", "销户", "修改密码","信息查看", "退出","欢迎使用ATM系统","用户菜单" };
    JButton[] jButtons = new JButton[8];

    public UserMenu() {
        Container containerPane = this.getContentPane();
        containerPane.setLayout(new GridLayout(3, 1));
        for (int i = 0; i < jPanels.length; i++) {
            jPanels[i] = new JPanel();
            if (i==0)
                jPanels[i].add(new JLabel(prompt[8]));
            else
                for (int j = 0; j < 4; j++) {
                    jButtons[(i-1)*4+j] = new JButton(prompt[(i-1)*4+j]);
                    jPanels[i].add(jButtons[(i-1)*4+j]);
                    jButtons[(i-1)*4+j].addActionListener(this);
                }
            containerPane.add(jPanels[i]);
        }
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setSize(500, 300);
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        setLocation((screen.width - 500) / 2, (screen.height - 300) / 2);
        setTitle(prompt[8]);
        setVisible(true);
    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == jButtons[0]) {
            new Deposit();
            dispose();
        } else if (e.getSource() == jButtons[1]) {
            dispose();
            new Withdrawal();
        } else if (e.getSource() == jButtons[2]) {
            dispose();
            new Transfer();
        } else if (e.getSource() == jButtons[3]) {
            dispose();
            new Investment();
        } else if (e.getSource() == jButtons[4]) {
            dispose();
            new Logout();
        } else if(e.getSource()==jButtons[5]){
            dispose();
            new ChangePassword();
        }else if (e.getSource() == jButtons[6]) {
            dispose();
            new AccountInformation();
        } else if (e.getSource() == jButtons[7]) {
            dispose();
        }
    }

    public static void main(String[] args) {
        new UserMenu();
    }
}
